import 'package:flutter/material.dart';
import 'package:flutter_color_plugin/flutter_color_plugin.dart';
import 'package:yw_bapp/widgets/wrap_gesture_widget.dart';

class TopImageWithText extends StatelessWidget {
  final String title;
  final String imageUrl;
  final TextStyle textStyle;
  final Function func;

  const TopImageWithText(
      {Key key, this.title, this.imageUrl, this.textStyle, this.func})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    bool isNetWork =
        imageUrl?.indexOf("http") != -1 ?? false ? true : false; //判断是不是网络图片路径
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          // 图片
          Container(
            margin: EdgeInsets.only(bottom: 8),
            child: wrapGesture(
                function: func,
                child: imageUrl != ''
                    ? isNetWork
                        ? Image.network(
                            "$imageUrl",
                            width: 36,
                            height: 36,
                            fit: BoxFit.cover,
                          )
                        : Image.asset("$imageUrl")
                    : Text('')),
          ),
          // 文字
          DefaultTextStyle(
            style: TextStyle(color: ColorUtil.color("#FF666666"), fontSize: 12),
            child: Text(
              "$title",
              style: textStyle,
            ),
          ),
        ],
      ),
    );
  }
}
